﻿<views:MvxWpfView
    xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:vms="clr-namespace:Sidvall.WorkItemManager.UI.ViewModels;assembly=Sidvall.WorkItemManager.UI"
    xmlns:Controls="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Controls" 
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
    xmlns:local="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Views"
    xmlns:Converters1="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Converters"
    x:Class="Sidvall.WorkItemManager.UI.Wpf.Views.MonitorContextView"
    mc:Ignorable="d" 
    d:DesignHeight="450" d:DesignWidth="600">

    <views:MvxWpfView.Resources>
        <Converters1:StringToTimeSpanConverter x:Key="StringToTimeSpanConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" Not="True"/>
    </views:MvxWpfView.Resources>

    <Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:MonitorContextViewModel}}">
        <TabControl>
            <TabItem Header="Monitored Server">
                <ScrollViewer VerticalScrollBarVisibility="Auto" IsEnabled="{Binding CanEdit}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition/>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel>
                            <Grid Margin="5,5,5,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="130" />
                                    <ColumnDefinition />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Label Content="Type"/>
                                <ComboBox Grid.Column="1" ItemsSource="{Binding ConnectionTypes}" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding ActiveEntity.ConnectionTypeId}"/>
                            </Grid>
                            <Grid Margin="5,5,5,0" Visibility="{Binding ShowRemoteConnection, Converter={StaticResource NotBooleanToVisibilityConverter}, Mode=OneWay}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="130" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Content="Connection String"/>
                                <TextBox Grid.Column="1" Text="{Binding ActiveEntity.ConnectionString}" />
                            </Grid>
                            <Grid Margin="5,5,5,0" Visibility="{Binding ShowRemoteConnection, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="130" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Label Content="Remote Address"/>
                                <TextBox Grid.Column="1" Text="{Binding ActiveEntity.RemoteAddress}" />
                            </Grid>
                            <Grid Margin="0,5,5,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="130" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Button Grid.Column="1" Background="{x:Null}" BorderBrush="{x:Null}" Command="{Binding ConnectToServerCommand}" HorizontalAlignment="Left">
                                    <StackPanel Orientation="Horizontal">
                                        <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/ConnectToServer.png" Width="36" Height="36" ToolTip="Connect to server" />
                                        <Label Content="Connect to server" />
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </StackPanel>
                    </Grid>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Monitored Tasks">
                <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                    <Grid>
                        <Grid Visibility="{Binding MonitoredWorkItemListIsVisible, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Grid Grid.ColumnSpan="3" IsEnabled="{Binding CanEdit}">
                                <Grid.Background>
                                    <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                </Grid.Background>
                                <StackPanel Orientation="Horizontal">
                                    <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Add.png" 
                                        ToolTip="Add monitored task" ButtonCommand="{Binding AddMonitoredWorkItemCommand}" />
                                </StackPanel>
                            </Grid>

                            <DataGrid Grid.Row="1" RowHeaderWidth="0" ItemsSource="{Binding ActiveEntity.MonitoredWorkItems}" AutoGenerateColumns="False" CanUserAddRows="False" RowHeight="55" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserResizeRows="False" SelectedItem="{Binding ActiveMonitoredWorkItem}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MouseDoubleClick">
                                        <i:InvokeCommandAction Command="{Binding EditMonitoredWorkItemCommand}" CommandParameter="{Binding ActiveMonitoredWorkItem}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                                <DataGrid.Columns>
                                    <DataGridTemplateColumn Width="60" Header="Enabled">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                                          HorizontalContentAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center"
                                                          IsEnabled="{Binding DataContext.CanEdit, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MonitorContextView}}}" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="*" Header="Task">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Description}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                    Command="{Binding DataContext.EditMonitoredWorkItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MonitorContextView}}}"
                                                    CommandParameter="{Binding}">
                                                    <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Edit.png" ToolTip="Edit monitored task" />
                                                </Button>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                    Command="{Binding DataContext.DeleteMonitoredWorkItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MonitorContextView}}}"
                                                    CommandParameter="{Binding}"
                                                    Visibility="{Binding DataContext.CanEdit, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MonitorContextView}}}">
                                                    <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Delete.png" ToolTip="Delete monitored task" />
                                                </Button>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                </DataGrid.Columns>
                            </DataGrid>
                        </Grid>
                        <Grid Visibility="{Binding MonitoredWorkItemListIsVisible, Converter={StaticResource NotBooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <Grid Grid.ColumnSpan="3">
                                <Grid.Background>
                                    <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                </Grid.Background>
                                <StackPanel Orientation="Horizontal">
                                    <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Back.png" 
                                        ToolTip="Back to list" ButtonCommand="{Binding ShowMonitoredWorkItemListCommand}" />
                                </StackPanel>
                            </Grid>
                            <StackPanel Grid.Row="1" IsEnabled="{Binding CanEdit}">
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="280" />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Task:"/>
                                    <ComboBox Grid.Column="1" ItemsSource="{Binding WorkItems}" SelectedValuePath="WorkItemId" DisplayMemberPath="Name" SelectedValue="{Binding ActiveMonitoredWorkItem.WorkItemId}" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Enabled:"/>
                                    <CheckBox Grid.Column="1" IsChecked="{Binding ActiveMonitoredWorkItem.IsEnabled}" VerticalAlignment="Center" />
                                </Grid>
                                <Rectangle Margin="0,5,5,5" StrokeEndLineCap="Round" Height="3" Fill="#FF23232B" >
                                    <Rectangle.Effect>
                                        <DropShadowEffect/>
                                    </Rectangle.Effect>
                                </Rectangle>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="80" />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Max Failed Executions:"/>
                                    <xctk:IntegerUpDown Grid.Column="1" Value="{Binding ActiveMonitoredWorkItem.MaxFailedExecutionCount}" ClipValueToMinMax="True" ParsingNumberStyle="Integer" Width="50" HorizontalAlignment="Left" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="80" />
                                    </Grid.ColumnDefinitions>

                                    <Label Grid.Column="0" Content="Alarm Timeout:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveMonitoredWorkItem.MaxFailedExecutionAlarmTimeout, Converter={StaticResource StringToTimeSpanConverter}, Mode=TwoWay}" />
                                </Grid>
                                <Rectangle Margin="0,5,5,5" StrokeEndLineCap="Round" Height="3" Fill="#FF23232B" >
                                    <Rectangle.Effect>
                                        <DropShadowEffect/>
                                    </Rectangle.Effect>
                                </Rectangle>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="80" />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Max Execution Time:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveMonitoredWorkItem.MaxExecutionTime, Converter={StaticResource StringToTimeSpanConverter}, Mode=TwoWay}" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="80" />
                                    </Grid.ColumnDefinitions>

                                    <Label Grid.Column="0" Content="Alarm Timeout:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveMonitoredWorkItem.MaxExecutionTimeAlarmTimeout, Converter={StaticResource StringToTimeSpanConverter}, Mode=TwoWay}" />
                                </Grid>
                                <Rectangle Margin="0,5,5,5" StrokeEndLineCap="Round" Height="3" Fill="#FF23232B" >
                                    <Rectangle.Effect>
                                        <DropShadowEffect/>
                                    </Rectangle.Effect>
                                </Rectangle>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="80" />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Max Idle Time:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveMonitoredWorkItem.MaxIdleTime, Converter={StaticResource StringToTimeSpanConverter}, Mode=TwoWay}" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="80" />
                                    </Grid.ColumnDefinitions>

                                    <Label Grid.Column="0" Content="Alarm Timeout:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveMonitoredWorkItem.MaxIdleTimeAlarmTimeout, Converter={StaticResource StringToTimeSpanConverter}, Mode=TwoWay}" />
                                </Grid>
                                <Rectangle Margin="0,5,5,5" StrokeEndLineCap="Round" Height="3" Fill="#FF23232B" >
                                    <Rectangle.Effect>
                                        <DropShadowEffect/>
                                    </Rectangle.Effect>
                                </Rectangle>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="200" />
                                        <ColumnDefinition Width="5" />
                                        <ColumnDefinition Width="120" />
                                        <ColumnDefinition Width="5" />
                                        <ColumnDefinition Width="120" />
                                    </Grid.ColumnDefinitions>

                                    <Label Content="Sensor:"/>
                                    <ComboBox Grid.Column="1" ItemsSource="{Binding ActiveWorkItem.WorkItemSensors}" SelectedValuePath="Name" DisplayMemberPath="Name" SelectedValue="{Binding ActiveMonitoredWorkItem.SensorName}" />
                                    <ComboBox Grid.Column="3" ItemsSource="{Binding ComparisonOperators}" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding ActiveMonitoredWorkItem.SensorComparisonOperator}" />
                                    <TextBox Grid.Column="5" Text="{Binding ActiveMonitoredWorkItem.SensorValue}" />
                                </Grid>
                                <Grid Margin="0,5,5,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="140" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="100" />
                                        <ColumnDefinition Width="80" />
                                    </Grid.ColumnDefinitions>

                                    <Label Grid.Column="0" Content="Alarm Timeout:"/>
                                    <TextBox Grid.Column="1" Text="{Binding ActiveMonitoredWorkItem.SensorAlarmTimeout, Converter={StaticResource StringToTimeSpanConverter}, Mode=TwoWay}" />
                                </Grid>
                            </StackPanel>
                        </Grid>
                    </Grid>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Email Settings">
                <ScrollViewer VerticalScrollBarVisibility="Auto" IsEnabled="{Binding CanEdit}">
                    <StackPanel>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="From:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.FromAddress}" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="To:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.RecipientAddresses}" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="CC:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.CCRecipientAddresses}" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="BCC:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.BccRecipientAddresses}" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="Subject:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.Subject}" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="Message:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.Body}" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Height="60" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <CheckBox Grid.Column="1" Content="Body is html" IsChecked="{Binding ActiveEntity.IsBodyHtml}" />
                        </Grid>
                        <Rectangle Margin="0,5,5,0" StrokeEndLineCap="Round" Height="3" Fill="#FF23232B" >
                            <Rectangle.Effect>
                                <DropShadowEffect/>
                            </Rectangle.Effect>
                        </Rectangle>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="Smtp Server:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.SmtpServer}" />
                        </Grid>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="SMS Settings">
                <ScrollViewer VerticalScrollBarVisibility="Auto" IsEnabled="{Binding CanEdit}">
                    <StackPanel>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="Web Address:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.SmsWebAddress}" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="Mobile:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.MobileNumber}" />
                        </Grid>
                        <Grid Margin="0,5,5,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="80" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Label Content="Message:"/>
                            <TextBox Grid.Column="1" Text="{Binding ActiveEntity.SmsBody}" AcceptsReturn="False" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" Height="60" />
                        </Grid>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
        </TabControl>
    </Grid>
</views:MvxWpfView>
